#include "object.h"
#include "graphic_2d_object.h"
#include "graphic_2d_quad.h"
/*--------------------------------------------------------------------------------*/
GRAPHIC_2D_QUAD::GRAPHIC_2D_QUAD()
   : GRAPHIC_2D_OBJECT()
 {
	ComputeVertexTable();
 }
/*--------------------------------------------------------------------------------*/
GRAPHIC_2D_QUAD::GRAPHIC_2D_QUAD( const MATH_VECTOR_2 & position, const MATH_VECTOR_2 & extent )
   : GRAPHIC_2D_OBJECT()
{
	Position = position;
	Extent = extent;
    ComputeVertexTable();
}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_QUAD::ComputeVertexTable()
{
    REAL
    	half_size_x( Extent.X * 0.5f ),
    	half_size_y( Extent.Y * 0.5f );

    VertexTable.SetItemCount( 6 );

    // Triangle 1
    VertexTable[0].Position = Position + MATH_VECTOR_2( - half_size_x, + half_size_y );
    VertexTable[1].Position = Position + MATH_VECTOR_2( + half_size_x, + half_size_y );
    VertexTable[2].Position = Position + MATH_VECTOR_2( + half_size_x, - half_size_y );
    VertexTable[0].UV.Set( 0.0f, 1.0f );
    VertexTable[1].UV.Set( 1.0f, 1.0f );
    VertexTable[2].UV.Set( 1.0f, 0.0f );

    // Triangle 2
    VertexTable[3].Position = VertexTable[2].Position;
    VertexTable[4].Position = Position + MATH_VECTOR_2( - half_size_x, - half_size_y );
    VertexTable[5].Position = VertexTable[0].Position;
    VertexTable[3].UV = VertexTable[2].UV;
    VertexTable[4].UV.Set( 0.0f, 0.0f );
    VertexTable[5].UV = VertexTable[0].UV;

    // :TODO: sin & cos to apply rotation

}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_QUAD::SetUVCoord( const GRAPHIC_TEXTURE_SET::UV_COORD & coord )
{
	VertexTable[0].UV.Set( coord.Start.X , coord.End.Y );
	VertexTable[1].UV.Set( coord.End.X, coord.End.Y );
	VertexTable[2].UV.Set( coord.End.X, coord.Start.Y );
	VertexTable[3].UV = VertexTable[2].UV;
	VertexTable[4].UV.Set( coord.Start.X , coord.Start.Y );
	VertexTable[5].UV = VertexTable[0].UV;
}
/*--------------------------------------------------------------------------------*/
